package com.augurit.wf.app.notice.web;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.wf.app.notice.service.INoticeService;
import com.augurit.wf.app.notice.web.form.NoticeForm;
import com.augurit.wf.bi.web.form.WfBusInstanceTaskForm;
import com.augurit.wf.common.constant.WfConstant;
import com.augurit.wf.common.entity.Notice;
import com.augurit.wf.common.service.IWfBusClientService;
import com.augurit.wf.common.util.WfUtils;
import com.augurit.wf.common.web.WfBusClientAction;
import com.augurit.wf.common.web.WfBusClientExtAction;

/**
 * 公告板管理Action类
 */
@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "notice.action", type = "redirect"),
	@Result(name = CrudActionSupport.INPUT, location = "/wf/app/notice/notice-input.jsp"),
	@Result(name = WfConstant.PRINT, location = WfConstant.PRINT_JSP),
})
public class NoticeAction extends WfBusClientExtAction<NoticeForm> {	
	
	@Autowired
	private INoticeService noticeService;	//公告板service类
	
	private NoticeForm form;	//公告板form对象
	private Long id;			//公告板id
	private Page<NoticeForm> page = new Page<NoticeForm>(10);
	
	
	/**
	 * 保存业务并关联流程实例
	 */
	public String wfBusSave() throws Exception {
		WfBusInstanceTaskForm task = this.wfBusSave((IWfBusClientService)noticeService, form, Notice.class.getSimpleName());
		WfUtils.renderWfBusSaveJson(task, form);
		return null;
	}
	
	/**
	 * 打印公告单
	 */
	public String printNotice() throws Exception {
		return WfUtils.wfBusPrint(form);
	}
	
	
	public String input() throws Exception {
		return INPUT;
	}
	
	/**
	 * 删除一个公告.
	 */
	@Override
	public String delete() throws Exception {
		
		//删除与公告对应的附件
		this.delete(Notice.class.getSimpleName(), id);
		
		//删除公告本身
		noticeService.delete(id);
		
		return RELOAD;
	}
	
	/**
	 * 分页查询公告板列表
	 */
	public String list() throws Exception {
		noticeService.search(page, form);
		return SUCCESS;
	}

	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			form = noticeService.get(id);
		}
		else
			form = new NoticeForm();
	}

	public NoticeForm getModel() {
		return form;
	}
	
	
	/************************************************
	 * 			get和set方法      					*
	 ************************************************/
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Page<NoticeForm> getPage() {
		return page;
	}

	public void setPage(Page<NoticeForm> page) {
		this.page = page;
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
}
	
